//
//  CaseDetailViewController.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/19.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "CaseDetailViewController.h"
#import "MLBlankView.h"
#import "MLButton.h"
#import "SelectCaseController.h"
#import "BingFaZhengController.h"
#import "CureTypeController.h"
#import "FocusDoctorController.h"

@interface CaseDetailViewController ()

@property (nonatomic, strong) UILabel *t_nameLabel; //t——开头的是title标题的意思
@property (nonatomic, strong) UILabel *nameLabel;   //姓名

@property (nonatomic, strong) UILabel *t_caseTypeLabel; //t——开头的是title标题的意思
@property (nonatomic, strong) UILabel *caseTypeLabel;

@property (nonatomic, strong) MLBlankView *view_selectCase; //选择疾病细分
@property (nonatomic, strong) UITextField *TF_selectCase;   //选择疾病细分 textfield

@property (nonatomic, strong) MLBlankView *view_bingFaCase; //并发症
@property (nonatomic, strong) UITextField *TF_bingFaCase;   //并发症

@property (nonatomic, strong) MLBlankView *view_sureCure;   //是否确诊
@property (nonatomic, strong) UITextField *TF_sureCure;     //是否确诊 textfield

@property (nonatomic, strong) MLBlankView *view_receiveCure; //是否接受治疗
@property (nonatomic, strong) UITextField *TF_receiveCure;   //是否接受治疗 textfield

@property (nonatomic, strong) MLBlankView *view_cureType;    //治疗方式
@property (nonatomic, strong) UITextField *TF_cureType;      //治疗方式 textfield

@property (nonatomic, strong) UILabel *docotCountLab; //医生数量

@property (nonatomic, strong) UIImageView *imgV;     //图像

@property (nonatomic, strong) UIButton *cureApplyButton; //就医申请


@property (nonatomic, strong) UIButton *leftButton_sureCure;
@property (nonatomic, strong) UIButton *rightButton_sureCure;
@property (nonatomic, strong) UIButton *leftButton_receiveReceive;
@property (nonatomic, strong) UIButton *rightButton_receiveReceive;

@end

@implementation CaseDetailViewController


- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"疾病详情选择";
    
    self.view.backgroundColor = kNaiBaiHuiColor;

    [self setupUI];
    [self configureUI];
    [self addLayouts];
    
 }


- (void)configureUI{

    NSString *titleString = nil;
    switch (self.caseDetailStyle) {
        case CaseDetailStyleZL:
            titleString = @"肿瘤";
            break;
        case CaseDetailStyleXXG:
            titleString = @"心血管";
            break;
        case CaseDetailStyleSJK:
            titleString = @"神经科";
            break;
        case CaseDetailStyleXYK:
            titleString = @"血液科";
            break;
        case CaseDetailStyleGK:
            titleString = @"骨科";
            break;
        default:
            break;
    }
    
    self.title = titleString;
    self.caseTypeLabel.text  = titleString;
}

- (void)setupUI{

    //1. 用户信息
    self.t_nameLabel = [[UILabel alloc] init];
    self.t_nameLabel.text = @"用户信息：";
    self.t_nameLabel.font = FONT(18);
    [self.view addSubview:self.t_nameLabel];
    
    //2. 疾病类型
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.text = @"王二狗 1000099";
    self.nameLabel.font = FONT(18);
    [self.view addSubview:self.nameLabel];
    
    //3. 用户信息
    self.t_caseTypeLabel = [[UILabel alloc] init];
    self.t_caseTypeLabel.text = @"疾病类型：";
    self.t_caseTypeLabel.font = FONT(18);
    [self.view addSubview:self.t_caseTypeLabel];
    
    //4. 疾病类型
    self.caseTypeLabel = [[UILabel alloc] init];
//    self.caseTypeLabel.text = @"肿瘤疾病";
    self.caseTypeLabel.font = FONT(18);
    [self.view addSubview:self.caseTypeLabel];
    
    //3.
    [self.view addSubview:self.view_selectCase];
    
    //4.
    [self.view addSubview:self.view_bingFaCase];
    
    //5.
    [self.view addSubview:self.view_sureCure];
    
    //6.
    [self.view  addSubview:self.view_receiveCure];
    
    //7.
    [self.view  addSubview:self.view_cureType];
    
    //8.
    self.docotCountLab  = [[UILabel alloc] init];
//    self.docotCountLab.backgroundColor = WHITE_COLOR;
    self.docotCountLab.text = @"为您匹配到：42 位医生";
    [self.view  addSubview:self.docotCountLab];
    
    //9.
    self.imgV  = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_img_person.png"]];
    [self.view  addSubview:self.imgV];
    
    //10
    self.cureApplyButton = [[UIButton alloc] init];
    [self.cureApplyButton setTitle:@"就医申请" forState:UIControlStateNormal];
    [self.cureApplyButton setTitleColor:WHITE_COLOR forState:UIControlStateNormal];
    self.cureApplyButton.backgroundColor = kThemeColor;
    self.cureApplyButton.layer.cornerRadius = 2;
    self.cureApplyButton.layer.masksToBounds = YES;
    [self.cureApplyButton addTarget:self action:@selector(clickCureApplyBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.cureApplyButton];
    
}

- (void)addLayouts{
    
    
    CGFloat view_BG_Height = 35*kProportion;
    CGFloat view_padding = 12*kProportion;
    
    CGFloat left_right_pagging = 15;
    
    [self.t_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(20+64);
        make.left.mas_equalTo(left_right_pagging);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.t_nameLabel.mas_top);
        make.left.mas_equalTo(self.t_nameLabel.mas_right).offset(10);
    }];
    
    [self.t_caseTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.t_nameLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(left_right_pagging);
    }];
    
    [self.caseTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.t_caseTypeLabel.mas_top);
        make.left.mas_equalTo(self.t_caseTypeLabel.mas_right).offset(10);
    }];
    

    
    [self.view_selectCase mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(left_right_pagging);
        make.top.mas_equalTo(self.t_caseTypeLabel.mas_bottom).offset(view_padding);
        make.right.mas_equalTo(-left_right_pagging);
        make.height.mas_equalTo(view_BG_Height);
    }];
    
    [self.view_bingFaCase mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.view_selectCase);
        make.top.mas_equalTo(self.view_selectCase.mas_bottom).offset(view_padding);
        make.height.mas_equalTo(view_BG_Height);
    }];
    
    [self.view_sureCure mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.view_selectCase);
        make.top.mas_equalTo(self.view_bingFaCase.mas_bottom).offset(view_padding);
        make.height.mas_equalTo(view_BG_Height);
    }];
    
    [self.view_receiveCure mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.view_selectCase);
        make.top.mas_equalTo(self.view_sureCure.mas_bottom).offset(view_padding);
        make.height.mas_equalTo(view_BG_Height);
    }];
    
    [self.view_cureType mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.view_selectCase);
        make.top.mas_equalTo(self.view_receiveCure.mas_bottom).offset(view_padding);
        make.height.mas_equalTo(view_BG_Height);
    }];
    
    
    [self.docotCountLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(200, 20));
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.bottom.mas_equalTo(self.imgV.mas_top).offset(-2*view_padding);
        
    }];
    
    [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(65*kProportion, 65*kProportion));
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.bottom.mas_equalTo(self.cureApplyButton.mas_top).offset(-2*view_padding);
    }];
    
    [self.cureApplyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(-view_padding);
        make.height.mas_equalTo(view_BG_Height);
    }];
    
}


#pragma mark  - Lazy
#pragma mark  - 疾病细分
-(MLBlankView *)view_selectCase{
    
    if (_view_selectCase == nil) {
        _view_selectCase = [[MLBlankView alloc] init];
        
        //1.
        UITextField *textfield = [[UITextField alloc] init];
        textfield.placeholder = @"请选择疾病细分";
//        textfield.backgroundColor = RED_COLOR;
        [_view_selectCase addSubview:textfield];
        textfield.userInteractionEnabled = NO;
        self.TF_selectCase = textfield;
        
        
        //2.
        UIView *lineV = [[UIView alloc] init];
        lineV.backgroundColor = LIGHT_GRAY_COLOR;
        [_view_selectCase addSubview:lineV];
        
        //3.
        UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
        [_view_selectCase addSubview:imgV];
        
        //约束
        [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.size.mas_equalTo(CGSizeMake(8, 10));
            make.right.mas_equalTo(_view_selectCase.mas_right).offset(-20);
            make.centerY.mas_equalTo(_view_selectCase.mas_centerY);
        }];
        
        [lineV mas_makeConstraints:^(MASConstraintMaker *make) {

            make.width.mas_equalTo(1);
            make.top.mas_equalTo(_view_selectCase.mas_top).offset(10);
            make.bottom.mas_equalTo(_view_selectCase.mas_bottom).offset(-10);
            make.right.mas_equalTo(imgV.mas_left).offset(-20);
            
        }];
        
        [textfield mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(_view_selectCase).offset(10);
            make.top.mas_equalTo(_view_selectCase.mas_top).offset(0);
            make.bottom.mas_equalTo(_view_selectCase.mas_bottom).offset(-0);
            make.right.mas_equalTo(lineV.mas_left).offset(-20);
        }];
        
        ///添加手势
        _view_selectCase.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap:)];
        [_view_selectCase addGestureRecognizer:tap];
        
    }
    return _view_selectCase;
}

#pragma mark  - 并发症
-(MLBlankView *)view_bingFaCase{
    
    if (_view_bingFaCase== nil) {
        _view_bingFaCase = [[MLBlankView alloc] init];
        
        //1.
        UITextField *textfield = [[UITextField alloc] init];
        textfield.placeholder = @"请选择并发症（可多选）";
//        textfield.backgroundColor = RED_COLOR;
        [_view_bingFaCase addSubview:textfield];
        textfield.userInteractionEnabled = NO;
        self.TF_bingFaCase = textfield;

        
        //2.
        UIView *lineV = [[UIView alloc] init];
        lineV.backgroundColor = LIGHT_GRAY_COLOR;
        [_view_bingFaCase addSubview:lineV];
        
        //3.
        UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
        [_view_bingFaCase addSubview:imgV];
        
        //约束
        [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.size.mas_equalTo(CGSizeMake(8, 10));
            make.right.mas_equalTo(_view_bingFaCase.mas_right).offset(-20);
            make.centerY.mas_equalTo(_view_bingFaCase.mas_centerY);
        }];
        
        [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.mas_equalTo(1);
            make.top.mas_equalTo(_view_bingFaCase.mas_top).offset(10);
            make.bottom.mas_equalTo(_view_bingFaCase.mas_bottom).offset(-10);
            make.right.mas_equalTo(imgV.mas_left).offset(-20);
            
        }];
        
        [textfield mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(_view_bingFaCase).offset(10);
            make.top.mas_equalTo(_view_bingFaCase.mas_top).offset(0);
            make.bottom.mas_equalTo(_view_bingFaCase.mas_bottom).offset(-0);
            make.right.mas_equalTo(lineV.mas_left).offset(-20);
        }];
        
        ///添加手势
        _view_bingFaCase.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap:)];
        [_view_bingFaCase addGestureRecognizer:tap];

    }
    return _view_bingFaCase;
}

#pragma mark  - 是否确诊
-(MLBlankView *)view_sureCure{
    
    if (_view_sureCure == nil) {
        _view_sureCure = [[MLBlankView alloc] init];
        
        //0.
        UITextField *textfield = [[UITextField alloc] init];
        textfield.placeholder = @"是否确诊";
//        textfield.backgroundColor = RED_COLOR;
        [_view_sureCure addSubview:textfield];
        textfield.userInteractionEnabled = NO;
        self.TF_sureCure = textfield;

        
        //1.
        MLButton *leftBtn = [MLButton buttonCreatedWithTitle:@"已确诊" font:16 titleColor:BLACK_COLOR norImage:@"illness_rb_img_nor.png" selectImg:@"illness_rb_img_sel.png"];
        leftBtn.tag = 101;
        [leftBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_view_sureCure addSubview:leftBtn];
        leftBtn.selected = YES;
        self.leftButton_sureCure = leftBtn;
        
        //2.
        MLButton *rightBtn = [MLButton buttonCreatedWithTitle:@"症状疑似" font:16 titleColor:BLACK_COLOR norImage:@"illness_rb_img_nor.png" selectImg:@"illness_rb_img_sel.png"];
        rightBtn.tag = 102;
        [rightBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_view_sureCure addSubview:rightBtn];
        self.rightButton_sureCure = rightBtn;
        
        [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.mas_equalTo(_view_sureCure).offset(-5);
            make.centerY.mas_equalTo(_view_sureCure);
            make.size.mas_equalTo(CGSizeMake(100*kProportion6, 30));
        }];
        
        [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.mas_equalTo(rightBtn.mas_left).offset(0);
            make.centerY.mas_equalTo(_view_sureCure);
            make.size.mas_equalTo(CGSizeMake(90*kProportion6, 30));
        }];
        
        [textfield mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(_view_sureCure).offset(10);
            make.top.mas_equalTo(_view_sureCure.mas_top).offset(0);
            make.bottom.mas_equalTo(_view_sureCure.mas_bottom).offset(-0);
            make.right.mas_equalTo(leftBtn.mas_left).offset(0);
        }];
    }
    return _view_sureCure;
}

#pragma mark  - 是否接受治疗
-(MLBlankView *)view_receiveCure{
    
    if (_view_receiveCure == nil) {
        _view_receiveCure = [[MLBlankView alloc] init];
        
        //0.
        UITextField *textfield = [[UITextField alloc] init];
        textfield.placeholder = @"是否接受过治疗";
//        textfield.backgroundColor = RED_COLOR;
        textfield.font = FONT(15);
        [_view_receiveCure addSubview:textfield];
        textfield.userInteractionEnabled = NO;
        self.TF_receiveCure = textfield;

        
        //1.
        MLButton *leftBtn = [MLButton buttonCreatedWithTitle:@"接受过" font:16 titleColor:BLACK_COLOR norImage:@"illness_rb_img_nor.png" selectImg:@"illness_rb_img_sel.png"];
        leftBtn.tag = 201;
        [leftBtn addTarget:self action:@selector(clickReciveBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_view_receiveCure addSubview:leftBtn];
        self.leftButton_receiveReceive = leftBtn;
        
        //2.
        MLButton *rightBtn = [MLButton buttonCreatedWithTitle:@"未接受过" font:16 titleColor:BLACK_COLOR norImage:@"illness_rb_img_nor.png" selectImg:@"illness_rb_img_sel.png"];
        rightBtn.tag = 202;
        [rightBtn addTarget:self action:@selector(clickReciveBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_view_receiveCure addSubview:rightBtn];
        self.rightButton_receiveReceive = rightBtn;
        rightBtn.selected = YES;

        
        [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.mas_equalTo(_view_receiveCure).offset(-5);
            make.centerY.mas_equalTo(_view_receiveCure);
            make.size.mas_equalTo(CGSizeMake(100*kProportion6, 30));
        }];
        
        [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.mas_equalTo(rightBtn.mas_left).offset(0);
            make.centerY.mas_equalTo(_view_receiveCure);
            make.size.mas_equalTo(CGSizeMake(90*kProportion6, 30));
        }];
        
        [textfield mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(_view_receiveCure).offset(10);
            make.top.mas_equalTo(_view_receiveCure.mas_top).offset(0);
            make.bottom.mas_equalTo(_view_receiveCure.mas_bottom).offset(-0);
            make.right.mas_equalTo(leftBtn.mas_left).offset(0);
        }];
        
    }
    return _view_receiveCure;
}

#pragma mark  - 选择治疗方式
-(MLBlankView *)view_cureType{
    
    if (_view_cureType == nil) {
        _view_cureType = [[MLBlankView alloc] init];
        _view_cureType.hidden = YES;
        
        //1.
        UITextField *textfield = [[UITextField alloc] init];
        textfield.placeholder = @"请选择治疗方式";
        // textfield.backgroundColor = RED_COLOR;
        [_view_cureType addSubview:textfield];
        textfield.userInteractionEnabled = NO;
        self.TF_cureType = textfield;
        
        //2.
        UIView *lineV = [[UIView alloc] init];
        lineV.backgroundColor = LIGHT_GRAY_COLOR;
        [_view_cureType addSubview:lineV];
        
        //3.
        UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
        [_view_cureType addSubview:imgV];
        
        //约束
        [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.size.mas_equalTo(CGSizeMake(8, 10));
            make.right.mas_equalTo(_view_cureType.mas_right).offset(-20);
            make.centerY.mas_equalTo(_view_cureType.mas_centerY);
        }];
        
        [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.mas_equalTo(1);
            make.top.mas_equalTo(_view_cureType.mas_top).offset(10);
            make.bottom.mas_equalTo(_view_cureType.mas_bottom).offset(-10);
            make.right.mas_equalTo(imgV.mas_left).offset(-20);
            
        }];
        
        [textfield mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(_view_cureType).offset(10);
            make.top.mas_equalTo(_view_cureType.mas_top).offset(0);
            make.bottom.mas_equalTo(_view_cureType.mas_bottom).offset(-0);
            make.right.mas_equalTo(lineV.mas_left).offset(-20);
        }];
        
        ///添加手势
        _view_cureType.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap:)];
        [_view_cureType addGestureRecognizer:tap];
    }
    return _view_cureType;
}

#pragma mark  - Actions
/** 点击 就医申请 */
- (void)clickCureApplyBtn:(UIButton *)btn{

    loggerImpt(@"点击 就医申请");
    
    FocusDoctorController *focusDoctor = [[FocusDoctorController alloc] init];
    
    [self.navigationController pushViewController:focusDoctor animated:YES];
}

/** 点击 是否确认 */
-(void)clickBtn:(UIButton *)btn{
    
    if (btn.tag==101) {
        
        self.leftButton_sureCure.selected = YES;
        self.rightButton_sureCure.selected = NO;
        self.TF_sureCure.text = @"已确诊";
    }else{
    
        self.leftButton_sureCure.selected = NO;
        self.rightButton_sureCure.selected = YES;
        self.TF_sureCure.text = @"症状疑似";
    }

//     loggerImpt(@"点击 btn");
}

/** 点击 是否接受过治疗 */
-(void)clickReciveBtn:(UIButton *)btn{
    
    if (btn.tag==201) {
        
        self.leftButton_receiveReceive.selected = YES;
        self.rightButton_receiveReceive.selected = NO;
        self.view_cureType.hidden = NO;
        self.TF_receiveCure.text = @"接受过";
    }else{
        
        self.leftButton_receiveReceive.selected = NO;
        self.rightButton_receiveReceive.selected = YES;
        self.view_cureType.hidden = YES;
        self.TF_receiveCure.text = @"未接受过";
    }
}

/** 点击 view_selectCase */
- (void)clickTap:(UITapGestureRecognizer *)tap{

    MLBlankView *newView = (MLBlankView *)tap.view;
        
    WEAKSELF
    if (newView == self.view_selectCase) {
        
        SelectCaseController *newVc = [[SelectCaseController alloc] init];
        newVc.clickSelectCaseVCBlock = ^(NSString *str){
        
//             loggerWarn(@"str = %@",str);
            weakSelf.TF_selectCase.text = str;
        };
        [self.navigationController pushViewController:newVc animated:YES];
        
    }else if (newView == self.view_bingFaCase){
    
       BingFaZhengController * newVc = (BingFaZhengController *)[[BingFaZhengController alloc] init];
        newVc.clickBingFaZhengVCBlock = ^(NSString *str){
        
//            loggerWarn(@"返回的数据 = %@",str);
            weakSelf.TF_bingFaCase.text = str;
        };
        [self.navigationController pushViewController:newVc animated:YES];

    }else if (newView == self.view_cureType){
    
      CureTypeController * newVc = [[CureTypeController alloc] init];
        newVc.clickCureTypeVCBlock = ^(NSString *str){
        
            weakSelf.TF_cureType.text = str;
//            loggerWarn(@"str = %@",str);
        };
      [self.navigationController pushViewController:newVc animated:YES];

    }
}

@end
